#ifndef FLOOR_H
#define FLOOR_H

#include <string>
#include <glm/glm.hpp>
#include "camera.h"
#include "directional_light.h"

class Floor {
private:
	GLuint VBO, VAO;
	Shader* shader;
	GLuint textureID;
public:
	Floor();
	~Floor();

	void render(glm::mat4 model, glm::mat4 view, glm::mat4 projection, DirLight dirlight, glm::vec3 viewPos);
};

Floor::Floor() {
	float vertices[] = {
		-2.5f, -0.5f, -2.5f,  0.0f, 1.0f, 0.0f,
		 2.5f, -0.5f, -2.5f,  0.0f, 1.0f, 0.0f,
		 2.5f, -0.5f,  2.5f,  0.0f, 1.0f, 0.0f,
		 2.5f, -0.5f,  2.5f,  0.0f, 1.0f, 0.0f,
		-2.5f, -0.5f,  2.5f,  0.0f, 1.0f, 0.0f,
		-2.5f, -0.5f, -2.5f,  0.0f, 1.0f, 0.0f
	};
	shader = new Shader(std::string("shaders/floor.vert").c_str(), std::string("shaders/floor.frag").c_str());
	shader->use();

	glGenVertexArrays(1, &VAO);
	glGenBuffers(1, &VBO);

	glBindVertexArray(VAO);

	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)));
	glEnableVertexAttribArray(1);
}

Floor::~Floor() {
	glDeleteBuffers(1, &VBO);
	glDeleteVertexArrays(1, &VAO);
	delete shader;
}

void Floor::render(glm::mat4 model, glm::mat4 view, glm::mat4 projection, DirLight dirlight, glm::vec3 viewPos) {
	shader->use();

	shader->setFloat("material.shininess", 10.0f);

	shader->setMat4("model", model);
	shader->setMat4("view", view);
	shader->setMat4("projection", projection);
	shader->setMat4("lightSpaceMatrix", dirlight.getLightSpaceMatrix());

	shader->setVec3("dirlight.direction", dirlight.getLightDir());
	shader->setFloat("dirlight.ambient", dirlight.getAmbient());
	shader->setVec3("dirlight.lightColor", dirlight.getLightColor());

	shader->setVec3("viewPos", viewPos);

	glBindVertexArray(VAO);
	glDrawArrays(GL_TRIANGLES, 0, 6);
}
#endif
